package com.ruoyi.project.optimize.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.optimize.domain.ProjectOptimize;
import com.ruoyi.project.optimize.service.IProjectOptimizeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 改进项目Controller
 * 
 * @author ruoyi
 * @date 2023-03-18
 */
@RestController
@RequestMapping("/project/optimize")
public class ProjectOptimizeController extends BaseController
{
    @Autowired
    private IProjectOptimizeService projectOptimizeService;

    /**
     * 查询改进项目列表
     */
    @PreAuthorize("@ss.hasPermi('project:optimize:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectOptimize projectOptimize)
    {
        startPage();
        List<ProjectOptimize> list = projectOptimizeService.selectProjectOptimizeList(projectOptimize);
        return getDataTable(list);
    }

    /**
     * 导出改进项目列表
     */
    @PreAuthorize("@ss.hasPermi('project:optimize:export')")
    @Log(title = "改进项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectOptimize projectOptimize)
    {
        List<ProjectOptimize> list = projectOptimizeService.selectProjectOptimizeList(projectOptimize);
        ExcelUtil<ProjectOptimize> util = new ExcelUtil<ProjectOptimize>(ProjectOptimize.class);
        util.exportExcel(response, list, "改进项目数据");
    }

    /**
     * 获取改进项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:optimize:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(projectOptimizeService.selectProjectOptimizeById(id));
    }

    /**
     * 新增改进项目
     */
    @PreAuthorize("@ss.hasPermi('project:optimize:add')")
    @Log(title = "改进项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectOptimize projectOptimize)
    {
        return toAjax(projectOptimizeService.insertProjectOptimize(projectOptimize));
    }

    /**
     * 修改改进项目
     */
    @PreAuthorize("@ss.hasPermi('project:optimize:edit')")
    @Log(title = "改进项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectOptimize projectOptimize)
    {
        return toAjax(projectOptimizeService.updateProjectOptimize(projectOptimize));
    }

    /**
     * 删除改进项目
     */
    @PreAuthorize("@ss.hasPermi('project:optimize:remove')")
    @Log(title = "改进项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(projectOptimizeService.deleteProjectOptimizeByIds(ids));
    }
}
